package edu.tyut.game.service.impl;

import edu.tyut.game.dao.circle.CommentsDao;
import edu.tyut.game.dao.circle.FriendCircleDao;
import edu.tyut.game.model.Comment;
import edu.tyut.game.model.FriendCircle;
import edu.tyut.game.service.FriendCircleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class FriendCircleServiceImpl implements FriendCircleService {

    private FriendCircleDao circleDao;
    @Autowired
    public void setCircleDao(FriendCircleDao circleDao) {
        this.circleDao = circleDao;
    }

    private CommentsDao commentsDao;
    @Autowired
    public void setCommentsDao(CommentsDao commentsDao) {
        this.commentsDao = commentsDao;
    }

    // @CachePut(cacheNames = "friendCircle", key = "#friendCircle.id()")
    @Override
    public void postFriendCircle(FriendCircle friendCircle) {
        circleDao.insertFriendCircle(friendCircle);
    }

    // @CacheEvict(cacheNames = "friendCircle", key = "#fcId")
    @Override
    public int deleteFriendCircle(int fcId) {
        return circleDao.deleteFriendCircle(fcId);
    }

    // @CachePut(cacheNames = "friendCircle", key = "#friendCircle.id()")
    @Override
    public int editeFriendCircle(FriendCircle friendCircle) {
        return circleDao.updateFriendCircle(friendCircle);
    }


    // @Cacheable(cacheNames = "friendCircles", unless = "#result == null")
    @Override
    public List<FriendCircle> queryFriendCircle(String order) {
        return circleDao.getFriendCircles(order);
    }


    // @CachePut(cacheNames = "friendCircleLike", key = "#fcId")
    @Override
    public int addFriendCircleLike(int fcId) {
        return circleDao.addFriendCircleLike(fcId);
    }

    // @CachePut(cacheNames = "friendCircleLike", key = "#fcId")
    @Override
    public int subFriendCircleLike(int fcId) {
        return circleDao.subFriendCircleLike(fcId);
    }


    // @CachePut(cacheNames = "comment", key = "#comment.id()")
    @Override
    public void postComment(Comment comment) {
        commentsDao.insertComment(comment);
    }

    // @CacheEvict(cacheNames = "comment", key = "#id")
    @Override
    public int deleteComment(int id) {
        return commentsDao.deleteCommentById(id);
    }

    // @Cacheable(cacheNames = "comments")
    @Override
    public List<Comment> queryComment(int fcId) {
        return commentsDao.getComments(fcId);
    }

    // @CachePut(cacheNames = "commentLike", key = "#commentId")
    @Override
    public int addCommentLike(int commentId) {
        return commentsDao.addCommentLike(commentId);
    }

    // @CachePut(cacheNames = "commentLike", key = "#commentId")
    @Override
    public int subCommentLike(int commentId) {
        return commentsDao.subCommentLike(commentId);
    }
}
